# add_done_callback 方法：当线程完成后自动调用

import time
import functools
from concurrent.futures import ThreadPoolExecutor, as_completed


def eat(name):
    print(f'{name} is eating')
    time.sleep(10 - name)
    print(f'{name} is done')
    return f"{name} 's result"


if __name__ == '__main__':
    with ThreadPoolExecutor(max_workers=5) as executor:
        req = as_completed([executor.submit(eat, name) for name in range(10)])
        [i.add_done_callback(functools.partial(print, 'hello world')) for i in req]
        for i in req:
            print(i.result())
